﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Windows;
using Internet_Cafe.App_Code.DatabaseModel;
using System.Windows.Controls;
using Internet_Cafe.App_Code;
using Internet_Cafe;

namespace Internet_Cafe
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {

        private void MenuItem_Click(object sender, RoutedEventArgs e)
        {
            if (AppHelper.LoggedUser.isAdmin == true)
                return;
            DateTime dt = DateTime.Now;
            MenuItem mi = sender as MenuItem;
            if (mi != null)
            {
                ContextMenu cm = mi.CommandParameter as ContextMenu;
                if (cm != null)
                {
                    ComputerItem ci = cm.PlacementTarget as ComputerItem;
                    if (ci != null)
                    {
                        if(!ci.isActive)
                            ci.setActivePostpaid(dt);
                    }
                }
            }
        }

        private void MenuItem_Click_1(object sender, RoutedEventArgs e)
        {
            if(((App_Code.DatabaseModel.Bill)sender).isPayed == false)
                ((App_Code.DatabaseModel.Bill)sender).isPayed = true; 
        }

        private void MenuItem_Click_2(object sender, RoutedEventArgs e)
        {
            if (AppHelper.LoggedUser.isAdmin == true)
                return;
            MenuItem mi = sender as MenuItem;
            if (mi != null)
            {
                ContextMenu cm = mi.CommandParameter as ContextMenu;
                if (cm != null)
                {
                    ComputerItem ci = cm.PlacementTarget as ComputerItem;
                    if (ci != null)
                    {
                        if (ci.isActive)
                            ci.setInactive();
                    }
                }
            }
        }

        private void MenuItem_Click_3(object sender, RoutedEventArgs e)
        {
            if (AppHelper.LoggedUser.isAdmin == true)
                return;
            MenuItem mi = sender as MenuItem;
            if (mi != null)
            {
                ContextMenu cm = mi.CommandParameter as ContextMenu;
                if (cm != null)
                {
                    ComputerItem ci = cm.PlacementTarget as ComputerItem;
                    if (ci != null)
                    {
                        if (!ci.isActive)
                        {
                            Postpaid pp = new Postpaid(ci);
                            pp.ShowDialog();
                        }
                    }
                }
            }
            
        }

        private void MenuItem_Click_4(object sender, RoutedEventArgs e)
        {
            MenuItem mi = sender as MenuItem;
            if (mi != null)
            {
                ContextMenu cm = mi.CommandParameter as ContextMenu;
                if (cm != null)
                {
                    ComputerItem ci = cm.PlacementTarget as ComputerItem;
                    if (ci != null)
                    {
                        App_Code.DataBaseAccess.DbComputersAccess.Delete(ci.ID);
                    }
                }
            }
        }
    }
}
